package com.example.week11;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.Nullable;

public class MyService extends Service {
    public MyService() {
    }

    public void onCreate(){
        super.onCreate();
        Log.d("My service", "onCreate executed!");

    }
    public int onStrartCommand(Intent intent,int flags,int startId){
        String msg=intent.getStringExtra("message");
        Log.d("My service","onStartCommand executed!"+" intent:"+msg+", flags:"+flags+",startId"
                +startId);
        return super.onStartCommand(intent,flags,startId);

    }

    public class MyBinder extends Binder {
        public MyService getService(){
            return MyService.this;
        }
    }

    private MyBinder myBinder = new MyBinder();
    private String valueToShow = "我代表希望传出去的值";
    public String getValue(){return valueToShow;}

    @Override

    public void onDestroy(){
        Log.d("My service","onDestroy executed!");
        super.onDestroy();
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        String msg = intent.getStringExtra("message");
        Log.d("MyService","绑定时收到mainActivity intent"+msg);
        return myBinder;
    }

    public boolean onUnbind(Intent intent){
        Log.d("Myservice","散货就散伙--onUnbind executed！");
        return super.onUnbind(intent);
    }

    public String doSomeOperation(String str){
        Log.d("Myservice","收到MainActivity要求："+str);
        return "谁怕谁，跟一个！";
    }
}
